from django.http import HttpResponse
from django.utils.deprecation import MiddlewareMixin

class UserAgentMiddleware(MiddlewareMixin):
    def process_request(self, request):
        print(request.path)
        print("UserAgentMiddleware","process_request")


    def process_response(self, request, response):

        print("UserAgentMiddleware","process_response")
        if request.META.get("HTTP_USER_AGENT") in ["Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/140.0.0.0 Safari/537.36"]:
            pass
        else:
            return HttpResponse("非法请求")
        return response